// 封装一个axios请求先传入请求头
import axis from '@/utils/request.js'
import store from '@/store'
// 导出一个请求
export const login = data => {
  return axis({
    method: 'POST',
    url: '/app/v1_0/authorizations',
    data
  })
}
// 获取用户信息接口
export const userinfo = data => {
  return axis({
    method: 'GET',
    url: '/app/v1_0/user',
    // 发送请求头数据
    headers: {
      // 注意：该接口需要授权才能访问
      //       token的数据格式：Bearer token数据，注意 Bearer 后面有个空格
      Authorization: `Bearer ${store.state.token.token}`
    }
  })
}
// 频道列表接口
export const getUserChannels = () => {
  return axis({
    method: 'GET',
    url: '/app/v1_0/user/channels'
  })
}
// 获取频道列表里面的数据
export const getArticles = params => {
  return axis({
    method: 'GET',
    url: '/app/v1_1/articles',
    params
  })
}
// 获取所有的推荐列表
export const getAllChannels = () => {
  return axis({
    method: 'GET',
    url: '/app/v1_0/channels'
  })
}

/**
 * 添加用户频道
 */
export const addUserChannel = channels => {
  return axis({
    method: 'PATCH',
    url: '/app/v1_0/user/channels',
    data: {
      channels
    }
  })
}
/**
 * 删除用户频道
 */
export const deleteUserChannel = channelId => {
  return axis({
    method: 'DELETE',
    url: `/app/v1_0/user/channels/${channelId}`
  })
}

/**
 * 添加关注
 */
export const addFollow = userId => {
  return axis({
    axis: 'POST',
    url: '/app/v1_0/user/followings',
    data: {
      target: userId
    }
  })
}

/**
 * 取消关注
 */
export const deleteFollow = userId => {
  return axis({
    method: 'DELETE',
    url: `/app/v1_0/user/followings/${userId}`
  })
}
/**
 * 评论接口模块
 */
export function getComments(params) {
  return axis({
    method: 'GET',
    url: '/app/v1_0/comments',
    params
  })
}

/**
 * 对评论或评论回复点赞
 */
export function addCommentLike(commentId) {
  return axis({
    method: 'POST',
    url: '/app/v1_0/comment/likings',
    data: {
      target: commentId
    }
  })
}

/**
 * 取消对评论或评论回复点赞
 */
export function deleteCommentLike(commentId) {
  return axis({
    method: 'DELETE',
    url: `/app/v1_0/comment/likings/${commentId}`
  })
}
/**
 * 添加评论或评论回复
 */
export function addComment(data) {
  return axis({
    method: 'POST',
    url: '/app/v1_0/comments',
    data
  })
}
